<template>
  <div class="login">
    <div class="login-content"></div>
    <div class="login-form">
      <div class="login-form-content">
        <div class="login-form-icon">
          <i class="el-icon-s-shop"></i>
          <h2 class="login-h2">mall-admin-web</h2>
          <el-form :model="user" :rules="rules" ref="user" class="demo-ruleForm" @keyup.enter.native="submitForm(user)">
            <el-form-item prop="username">
              <el-input type="text" v-model="user.username" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input placeholder="请输入密码" v-model="user.password" show-password autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm(user)">提交</el-button>
              <el-button @click="resetForm">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchLoginInfo } from '@/api/api'
export default {
  name: 'Login',
  data() {
    return {
      input: '',
      user: {
        username: '',
        password: '',
      },
      rules: {
        username: [{ required: true, message: '用户名不能为空' }],
        password: [{ required: true, message: '密码不能为空' }],
      },
    }
  },
  methods: {
    submitForm() {
      fetchLoginInfo({ data: { ...this.user } }).then((res) => {
        console.log(res)
        if (res.code == 200) {
          localStorage.setItem('token', res.data.tokenHead + res.data.token)
          this.fullscreenLoading = true
          setTimeout(() => {
            this.fullscreenLoading = false
          }, 2000)
          this.$router.push('/layout').catch(() => {})
        } else {
          alert('用户名或密码错误')
        }
      })
    },
    resetForm() {
      this.user.username = ''
      this.user.password = ''
    },
  },
}
</script>

<style lang="scss" scoped>
.el-form-item__content {
  margin-bottom: 60px;
  text-align: center;
}
.el-icon-view {
  position: absolute;
  right: 13px;
  top: 11px;
  font-size: 20px;
}
.el-icon-s-shop {
  color: rgb(64, 158, 255);
  font-size: 60px;
}
.login-btn {
  color: #fff;
  background-color: #409eff;
  border-color: #409eff;
  line-height: 40px;
  position: relative;
  font-size: 14px;
  width: 45%;
}
.login-div {
  margin-bottom: 60px;
  text-align: center;
}
.login {
  height: 505px;
  width: 100%;
}
.login-content {
  width: 100%;
  height: 300px;
  margin-top: 200px;
  float: left;
  background: #409eff;
  background-image: url('../../assets/1.png');
}
.login-form {
  position: absolute;
  left: 0;
  right: 0;
  width: 360px;
  margin: 140px auto;
  border-top: 10px solid #409eff;
  background: #fff;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
}
.login-form-content {
  padding: 20px;
  margin-bottom: 60px;
}
.login-form-icon {
  text-align: center;
}
.svg-icon {
  width: 56px;
  height: 56px;
  color: rgb(64, 158, 255);
}
.login-h2 {
  color: #409eff;
  margin: 20px 0;
}
.input-text {
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 100%;
  border-color: #67c23a;
}
.input {
  position: relative;
  margin-bottom: 22px;
}
</style>
